Array.prototype.myReduce = function(Fn, initval) {
    if(typeof Fn != "function") {
        throw Error("无回调函数")
    }
    if(!this) return null;
    let prev = initval;
    let start = 0;
    if(initval === undefined) {
        prev = this[0];
        start ++;
    }
    for(let i = start; i < this.length; i++) {
        prev = Fn(prev, this[i], i, this)
    }
    return prev;
}

const arr = [1,2,3];
console.log(arr.myReduce((prev, item) => prev + item, 2))
console.log([].myReduce((prev, item) => prev + item))